function EPSC_mean_var()
% from a data set that has had the mean and varaince fo the first EPSC
% calculated, we plot mean/var and compute the N and P estimates
%
global CONTROL
%try
sf = getmainselection;
pflag = getplotflag;
if(length(sf) <= 2)
    QueMessage('Not enough data for this analysis', 1);
    return;
end;
QueMessage('EPSC analysis', 1); % clear the que
nds = length(sf);
m = zeros(nds+1, 1);
v = zeros(nds+1, 1);
for i = 1:length(sf)
    if(check_field(CONTROL(sf(i)), 'EPSC_Cov') && ~isempty(CONTROL(sf(i)).EPSC_Cov))
        E = CONTROL(sf(i)).EPSC_Cov;
        m(i+1) = -E.Im(1)/1000;
        v(i+1) = E.Ivar(1)/10^6;
    else
        return;
    end;
end;

[P, S] = polyfit(m, v, 2);
xf = [0:0.01:1];
yf = P(1)*xf.^2+P(2)*xf+P(3);
Pr = m(2)*(-P(1)/P(2));
Nmin = -(1/P(1));
hf = newfigure('EPSC_meanvar', 'EPSC Mean-Variance');
subplot(1,2, 1);

plot(m, v, 'ko', 'markerfacecolor', 'k', 'markeredgecolor', 'k', 'markersize', 3);
hold on;
plot(xf, yf, 'r-');
u = get(gca, 'Ylim');
set(gca, 'Ylim', [0 u(2)]);
v = get(gca, 'Xlim');
set(gca, 'Xlim', [0 v(2)]);


subplot(1, 2, 2);
axis([0,1,0,1])
axis('off')
text(0,0.9,sprintf('%-12s \nProtocol:%-8s',CONTROL(sf(1)).filename, CONTROL(sf(1)).protocol), 'Fontsize', 12);
text(0,0.8,sprintf('Pr: %8.2f  Nmin = %8.0f', Pr, Nmin), 'FontSize', 12);

if(pflag)
    eval (sprintf('print -f%d', findobj('tag', 'EPSC_meanvar')));
end;

    
